<template>
    <div>
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item', item.id == 0 ? 'mui-active' : '' ]" href="#item1mobile"
                       data-wid="tab-top-subpage-1.html" v-for="item in categoryList" :key="item.id" @click="getPhotoListByCategoryId(item.id)">
                        {{ item.title }}
                    </a>

                </div>
            </div>
        </div>


        <ul class="photo-list">
            <router-link v-for="item in photoList" :key="item.id" :to="'/home/photoinfo/' + item.id" tag="li">
                <img class="photo-img" v-lazy="item.img_url">
                <div class="info">
                    <h1 class="info-title">{{ item.title }}</h1>
                    <div class="info-body">{{ item.zhaiyao }}</div>
                </div>
            </router-link>
        </ul>
    </div>
</template>

<script>
    // 使用这个需要使用 npm install babel-plugin-transform-remove-strict-mode 移除严格模式
    import mui from '../../lib/mui/js/mui.min';


    export default {
        data() {
            return {
                categoryList: [],
                photoList: []
            }
        },
        created() {
            this.getCategories();
            this.getPhotoListByCategoryId('0');
        },
        methods: {
            // 获取分类
           getCategories() {
              this.$http.get('home/Categories.json').then( result => {
                 if (result.body.status === 0) {
                     this.categoryList = result.body.message;
                     this.categoryList.unshift({ title: '全部', id: 0});
                 }
              });
           },
           // 获取图片
            getPhotoListByCategoryId(categoryId) {
               this.$http.get('home/PhotoList.json').then( result => {
                   if (result.body.status === 0) {
                       this.photoList = [];
                       if (categoryId == '0') {
                           this.photoList = result.body.message;
                       } else if (categoryId == '1') {
                           this.photoList.push(result.body.message[0]);
                       } else if (categoryId == '2') {
                           this.photoList.push(result.body.message[1]);
                       } else if (categoryId == '3') {
                           this.photoList.push(result.body.message[2]);
                       } else if (categoryId == '4') {
                           this.photoList.push(result.body.message[3]);
                       } else if (categoryId == '5') {
                           this.photoList.push(result.body.message[4]);
                       } else if (categoryId == '6') {
                           this.photoList.push(result.body.message[5]);
                       }


                   }
               });
            }

        },
        mounted() {
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        }
    }
</script>

<style lang="scss" scoped>
* {
    /**用于解决滑动产生的异常：Unable to preventDefault inside passive event listener due to target being **/
    touch-action: pan-y;
}


   .photo-list {
       list-style: none;
       margin: 0;
       padding: 10px;
       padding-bottom: 0;
       li{
           background-color: #ccc;
           text-align: center;
           margin-bottom: 10px;
           box-shadow: 0 0 9px #999;
           position: relative;
           img {
               width:100%;
               vertical-align: middle;
           }
           img[lazy="loading"] {
               width: 40px;
               height: 300px;
               margin: auto;
           }

           .info {
               color: #ffffff;
               text-align: left;
               position: absolute;
               bottom: 0;
               background-color: rgba(0, 0, 0, 0.4);
               max-height: 84px;
               .info-title {
                   font-size: 14px;
               }
               .info-body {
                   font-size: 13px;
               }
           }
       }
   }



</style>
